#ifndef MAP3D_H
#define MAP3D_H

#include <QWidget>
#include "ui_map3d.h"
#include <alg_type_defs.h>
#include <thread>
#include <mutex>
#include <QThread>
#include <QDebug>
#include <QOpenGLWidget>


GEO_ALG_USE_NAMESPACE

Polygon3d rotate(const Polygon3d& src, double angle, Vector3d axis);
class Map3d : public QOpenGLWidget {
    Q_OBJECT

public:
    Map3d(QWidget* parent = 0);
    ~Map3d();

    void set_map_info(const QVector<Polygon2d> polygons);

    Point3d convert(double lat, double lon);
    void convert(const Polygon2d&, int& cnt, Polygon3d& out);
    void convert_update();
    virtual void paintEvent(QPaintEvent* event);
    void keyPressEvent(QKeyEvent* event);
public slots:
    void update_draw();
public:
    Ui::Map3d ui;

    QVector<Polygon2d> raw_polygons_;

    QVector<Polygon3d> polygons_;
    QVector<QColor > colors_;

    QVector<int> flags_;

    double degree_ = 90;
    double          view_lon_ = 0;
    std::mutex      mutex_;
    std::thread     thread_;
    bool            updated_ = false;
    bool            exit_ = false;
    QPointF         test_pos_;
    QPolygonF       equator_;
};

#endif // MAP3D_H
